package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Menu;
import com.itheima.health.service.MenuStatusService;
import com.itheima.health.service.RoleMenuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("menustatus")
//111
public class MenuStatusController {
    @DubboReference
    private MenuStatusService menuService;
    @DubboReference
    private RoleMenuService roleMenuService;

    @GetMapping("findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = menuService.findPage(queryPageBean);
        return new Result(true, MessageConst.ACTION_SUCCESS, pageResult);
    }

    @GetMapping("findById")
    public Result findById(Integer id) {
        Menu menu = menuService.findById(id);
        return new Result(true, MessageConst.ACTION_SUCCESS, menu);
    }

    @PostMapping("edit")
    public Result edit(@RequestBody Menu menu) {
        menuService.edit(menu);
        return new Result(true, MessageConst.ACTION_SUCCESS);

    }

    @PostMapping("add")
    public Result add(@RequestBody Menu menu) {
        menuService.add(menu);
        return new Result(true, MessageConst.ACTION_SUCCESS);
    }

    @GetMapping("findAll")
    public Result findAll() {
        List<Menu> menuList = menuService.findAll();
        return new Result(true, MessageConst.ACTION_SUCCESS, menuList);
    }

    @GetMapping("findmenuIdsById")
    public Result findmenuIdsById(Integer id) {
        List<Integer> menuIds = roleMenuService.findmenuIdsById(id);
        return new Result(true, MessageConst.ACTION_SUCCESS, menuIds);
    }
}
